$(function () {
    FastClick.attach(document.body);
    //弹框函数
    function tip(msg) {
        $(".pop_tip").show().text(msg);
        setTimeout(function () {
            $(".pop_tip").slideUp(500);
        }, 1000)
    }

    //用户id
    var uid =getQueryString('userid');
    var friendid=getQueryString('friendid');
    var butler;
    var stool=getQueryString('stool');
    if(stool==1){
        $(".gain").show();
        $("stool").hide()
    }else{
        $(".stool").show();
        $("gain").hide();
    }
    $(".back").on('click', function () {
        window.history.go(-1);
    });
    //收集功能是否点击
    var shouji = false;
    //进入页面显示用户基本信息
    var pm = {};
    pm.userid = friendid;
    getData({url: info, data: pm}, function (data) {
        setTimeout(function () {
            $('.loading').hide()
        },500)
        butler = data.butler;
        var umobile = data.mobile;
        var uweixin = data.wxid;
        if (data.newnotifystate == 1) {
            $('.new_msg').show()
        }
        //基本信息展示
        $('.lv span').text(data.level)
        $(".user_name").text(data.name);
        $(".user_id").text(data.userid);
        $(".user_mobile").text(data.mobile);
        $(".user_weixin").text(data.wxid);
        $(".user_alipay").text(data.alipayno);
        $(".user_recommend").text(data.recommender);
        $(".recommend_mobile").text(data.recommendermobile);
        $(".integral>span").eq(0).text(data.sesame);
        $(".integral>span").eq(1).children().text(data.points);
        if (data.photo != "") {
            $(".face>img").attr("src", serverurl + data.photo);
        }
        $(".name").text(data.name);
    });
    //植物信息列表
    var zhiwulistpm = {};
    zhiwulistpm.userid = friendid;
    getData({url: zhiwulist, data: zhiwulistpm}, function (res) {
        //红土地
        for (var i = 0; i < res.total; i++) {
            $(".tudi>div").eq(i).css("backgroundImage", 'url("imgs/hongtudi.png")');
        }
        //植物显示位置
        $(".zhiwupic_container").html(template("landTem", res));
        $(".fpic0").css({width: "65px", position: "absolute", left: "27%", top: "32%"});
        $(".fpic1").css({width: "65px", position: "absolute", left: "18%", top: "40%"});
        $(".fpic2").css({width: "65px", position: "absolute", left: "35%", top: "40%"});
        $(".fpic3").css({width: "65px", position: "absolute", left: "26%", top: "49%"});
        $(".fpic4").css({width: "65px", position: "absolute", left: "44%", top: "48%"});
        $(".fpic5").css({width: "65px", position: "absolute", left: "35%", top: "56%"});
        $(".fpic6").css({width: "65px", position: "absolute", left: "52%", top: "54%"});
        $(".fpic7").css({width: "65px", position: "absolute", left: "43%", top: "64%"});
        $(".fpic8").css({width: "65px", position: "absolute", left: "61%", top: "63%"});
        $(".fpic9").css({width: "65px", position: "absolute", left: "52%", top: "72%"});
        //点击植物查看信息或者收取
        $(".fpic").off('click').on("click", function (e) {
            if (!shouji) {

            } else {
            if (stool == 1) {
                var gainpm = {};
                gainpm.userid = uid;
                gainpm.fuserid = friendid;
                gainpm.userfruitid = $(this).attr("data-userfruitid");
                getData({url: gain, data: gainpm}, function (res) {
                    tip(res.info);
                })
            } else {
                var stoolpm = {};
                stoolpm.userid = uid;
                stoolpm.fuserid = friendid;
                stoolpm.userfruitid = $(this).attr("data-userfruitid");
                getData({url: stealurl, data: stoolpm}, function (res) {
                    tip(res.info);
                })

            }
        }
        });
        //收集植物
        var bool = [false, true];
        var boolcount = 0;
        $(".stool").off('click').on("click", function () {

            $(this).toggleClass('p1')
            boolcount++;
            shouji = bool[boolcount % 2];
//            $(this).toggleClass("animation");
        });
        $(".gain").off('click').on("click", function () {
            boolcount++;
            shouji = bool[boolcount % 2];
          $(this).toggleClass('p1')
//            $(this).toggleClass("animation");
        });
    });
    //设置
    setting();
    function setting() {
        $('.top_right li').eq(0).on('touchstart', function () {
            $('#box').show();
            $('.set_box').show();
        })
        //点击开关
        var au=document.getElementById('audio')
        $('.set_box_content .off_on').on('touchstart', function () {
            $(this).toggleClass('loop');
            if(au.paused){
                au.play();
            }else{
                au.pause();
            }
        });
        //点击注销
        $('.tuichu').off('touchstart').on('touchstart', function () {
            window.location.href='login.html'
        })
        $('.set_box .close').off('touchstart').on('touchstart', function () {
            $('.set_box').hide();
            $('#box').hide();
        })
    }
});
